package org.lhq.feign;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.lhq.entity.Share;
import org.lhq.entity.UserFile;
import org.lhq.entity.vo.ShareVO;
import org.lhq.service.IShareService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: admin-service
 * @description: 分享feign调用
 * @author: Wang defa
 * @create: 2021-01-07 10:08
 */

@RestController
@Slf4j
@RequestMapping("share-feign")
public class ShareFeign {
    @Resource
    private IShareService shareService;
    @GetMapping("{id}")
    public ShareVO getShare(@PathVariable("id") Long id){
        return shareService.getShareVO(id);
    }
    @PostMapping("page")
    IPage<Share> getSharerPage(@RequestBody Share share,
                                @RequestParam(required = false) Long size,
                                @RequestParam(required = false) Long pageNum){
        pageNum = pageNum ==null?1:pageNum;
        size = size == null?5:size;
        log.info("查找条件:{}",share);
        log.info("查找第几页:{}",pageNum);
        log.info("查找每页大小:{}",size);
        QueryWrapper<Share> shareQueryWrapper = null;
        if (share!=null&& StrUtil.isNotEmpty(share.getShareCode())&&StrUtil.isNotEmpty(share.getShareLink())){
            shareQueryWrapper = new QueryWrapper<>(share);
        }
        IPage<Share> shareFilePage = new Page<Share>().setSize(size).setCurrent(pageNum);
        return shareService.page(shareFilePage,shareQueryWrapper);
    }
}
